package com.gupao.edu.study.thread;

public class ConcurrentcyTest {
    private  static final long count = 100001;

    public static void main(String[] args) throws InterruptedException {
        concurrentcy();
        serial();
    }
    /*
     * @Author: guqy
     * @Description: 多线程计算
     * @Date 16:40 2018/3/15
     * @param
     * @return void
     */
    public static void concurrentcy() throws InterruptedException {
        long start = System.currentTimeMillis();
        Thread thread = new Thread(() ->{
            int a = 0;
            for (int i = 0; i < count; i++) {
                a += 5;
                System.out.println(a);
            }
        });
        thread.start();
        int b = 0;
        for (int i = 0; i < count; i++) {
            b--;
        }
        long end = System.currentTimeMillis();
        thread.join(300);
        System.out.println(b+"~~~~~~~~~~~~~~~~~~");
        System.out.println("concurrentcy耗时"+(end-start));
    }
    /*
     * @Author: guqy
     * @Description:单线程计算
     * @Date 16:47 2018/3/15
     * @param
     * @return void
     */
    public static void serial(){
        long start = System.currentTimeMillis();
        int a = 0;
        for (int i = 0; i < count; i++) {
            a += 5;
        }
        int b = 0;
        for (int i = 0; i < count; i++) {
            b--;
        }
        long end = System.currentTimeMillis();
        System.out.println("serial耗时"+(end-start));
    }
}
